﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TransCend.DB;
using TransCend.Model;
using TransCend.Util.Page;

namespace TransCend.DAL
{
    public interface IBaseDAL<T> where T : BaseModel
    {
        T FindByID(int id);

        /// <summary>
        /// 单个字段条件获取唯一记录对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyname"></param>
        /// <param name="propertyvalue"></param>
        /// <returns></returns>
        T FindByProperty(string propertyname, object propertyvalue);

        T FindByPropertys(string[] propertynames, object[] propertyvalues);

        int Insert(T model);

        int InsertReturnId(T model);
        /// <summary>
        /// 批量插入
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Insert(IList<T> models);

        int Update(T model);

        int Delete(int id);

        int Delete(int[] ids);

        /// <summary>
        /// 单个字段删除记录
        /// </summary>
        /// <typeparam name="int"></typeparam>
        /// <param name="propertyname"></param>
        /// <param name="propertyvalue"></param>
        /// <returns></returns>
        int DeleteByProperty(string propertyname, object propertyvalue);

        int DeleteByPropertys(string[] propertyname, object[] propertyvalue);
        /// <summary>
        /// 对主键为string类型的ID删除
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="id"></param>
        /// <returns></returns>
        int Delete(string id);

        /// <summary>
        /// 条件删除
        /// </summary>
        /// <param name="DBFied"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        int Delete(string DBFied, object value);

        /// <summary>
        /// 只更新DBFields中的字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <param name="DBFields"></param>
        /// <returns></returns>
        int UpdatePartially(T model, string[] DBFields);

        /// <summary>
        /// 对DBField字段计数，默认+1
        /// </summary>
        /// <param name="id"></param>
        /// <param name="DBField"></param>
        /// <returns></returns>
        int UpdateSetp(int id, string DBField);

        /// <summary>
        /// 对DBField字段计数，增+setp
        /// </summary>
        /// <param name="id"></param>
        /// <param name="DBField"></param>
        /// <param name="setp"></param>
        /// <returns></returns>
        int UpdateSetp(int id, string DBField, int setp);

        /// <summary>
        /// 合并，不更新model空值字段
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="model"></param>
        /// <returns></returns>
        int Merge(T model);

        /// <summary>
        /// 所有数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        IList<T> FindAll(params OrderBy[] orderBy);

        /// <summary>
        /// 根据单个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyname"></param>
        /// <param name="propertyvalue"></param>
        /// <returns></returns>
        IList<T> FindList(string propertyname, object propertyvalue, params OrderBy[] orderBy);

        /// <summary>
        /// 多个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertynames"></param>
        /// <param name="propertyvalues"></param>
        /// <returns></returns>
        IList<T> FindList(string[] propertynames, object[] propertyvalues, params OrderBy[] orderBy);

        /// <summary>
        /// 多个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queryModel">不为空的为查询条件</param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        IList<T> FindList(T queryModel, params OrderBy[] orderBy);

        IList<T> FindList(int[] ids, params OrderBy[] orderBy);

        PageTools<T> FindPage(int page, int rows, OrderBy[] orderBy);

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="rows"></param>
        /// <param name="queryModel">查询条件</param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        PageTools<T> FindPage(int page, int rows, T queryModel, OrderBy[] orderBy);

        /// <summary>
        /// 获取数据库当前时间
        /// </summary>
        /// <returns></returns>
        DateTime FindNowDate();

        int FindListCount(T queryModel, params OrderBy[] orderBy);
    }
}
